import 'package:flutter/material.dart';
import 'package:hkzf/widgets/common_floatingactionbutton.dart';
import 'package:hkzf/widgets/common_form_item.dart';
import 'package:hkzf/widgets/common_image_picker.dart';
import 'package:hkzf/widgets/common_radio_form_item.dart';
import 'package:hkzf/widgets/common_select_form_item.dart';
import 'package:hkzf/widgets/common_title.dart';
import 'package:hkzf/widgets/room_appliance.dart';

class RoomAddPage extends StatefulWidget {
  RoomAddPage({Key key}) : super(key: key);

  @override
  _RoomAddPageState createState() => _RoomAddPageState();
}

class _RoomAddPageState extends State<RoomAddPage> {
  int rentType = 0;
  int decorationType = 0;

  int roomType = 0;
  int floor = 0;
  int oriented = 0;

  List<RoomApplianceItem> checkedList;

  var titleController = TextEditingController();
  var descController = TextEditingController();
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('发布房源'),
      ),
      body: ListView(children: [
        CommonTitle('房源信息'),
        CommonFormItem(
          label: '小区',
          contentBuilder: (BuildContext context) {
            return GestureDetector(
                behavior: HitTestBehavior.translucent,
                onTap: () {
                  Navigator.of(context).pushNamed('search');
                },
                child: Container(
                  height: 50,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '请选择小区',
                        style: TextStyle(fontSize: 16),
                      ),
                      Icon(Icons.keyboard_arrow_right)
                    ],
                  ),
                ));
          },
        ),
        CommonFormItem(
          label: '租金',
          hintText: '请输入租金',
          suffixText: '元/月',
          controller: TextEditingController(),
        ),
        CommonFormItem(
          label: '大小',
          hintText: '请输入房屋大小',
          suffixText: '平方米',
          controller: TextEditingController(),
        ),
        CommonRadioFormItem(
            label: '租赁方式',
            options: ['合租', '整租'],
            value: rentType,
            onChange: (index) {
              setState(() {
                rentType = index;
              });
            }),
        CommonSelectFormItem(
          label: '户型',
          value: roomType,
          onChange: (val) {
            print(val);
            setState(() {
              roomType = val;
            });
          },
          options: [
            '一室',
            '二室',
            '三室',
            '四室',
          ],
        ),
        CommonSelectFormItem(
          label: '楼层',
          value: floor,
          onChange: (val) {
            setState(() {
              floor = val;
            });
          },
          options: [
            '高楼层',
            '中楼层',
            '低楼层',
          ],
        ),
        CommonSelectFormItem(
          label: '朝向',
          value: oriented,
          onChange: (val) {
            setState(() {
              oriented = val;
            });
          },
          options: [
            '东',
            '南',
            '西',
            '北京',
          ],
        ),
        CommonRadioFormItem(
            label: '装修',
            options: ['精装', '简装'],
            value: decorationType,
            onChange: (index) {
              setState(() {
                decorationType = index;
              });
            }),
        CommonTitle('房屋头像'),
        CommonImagePicker(
          onChange: (file) {},
        ),
        CommonTitle('房屋标题'),
        Container(
          margin: EdgeInsets.all(10),
          child: TextField(
            controller: titleController,
            decoration:
                InputDecoration(border: InputBorder.none, hintText: "请输入标题"),
          ),
        ),
        CommonTitle('房屋配置'),
        RoomAppliance(
          onChange: (List<RoomApplianceItem> list) {
            setState(() {
              this.checkedList = list;
            });
          },
        ),
        CommonTitle('房屋描述'),
        Container(
          margin: EdgeInsets.all(10),
          child: TextField(
            controller: descController,
            maxLines: 10,
            decoration:
                InputDecoration(border: InputBorder.none, hintText: "请输入描述"),
          ),
        ),
      ]),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      floatingActionButton: CommonFloatingActionButton('提交', () {}),
    );
  }
}
